package my.interceptor;

import java.util.Map;

import my.db.DBManager;
import my.utils.Constant;
import net.sinodata.blog.domain.authorize.User;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class ControllerInterceptor extends MethodFilterInterceptor implements Constant {
	private static final long serialVersionUID = 1L;
	private static final Log log = LogFactory.getLog(ControllerInterceptor.class);

	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		log.debug("ControllerInterceptor doIntercept");
		Map<String, Object> session = invocation.getInvocationContext().getSession();
		String view = ACTION_RESULT_LOGIN;
		try {
			Object obj = session.get(SESSION_USER);
			if (null!=obj && obj instanceof User){
				view = invocation.invoke();
			}
		} finally {
			DBManager.closeConnection();
		}
		return view;
	}
}
